Can I connect my SMS Gateway to Nagios, Icinga 1 or Icinga 2?

 

 

1. Nagios + Icinga 1

 

You can of course use your SMS Gateway to send alarms from Nagios or Icinga 1 via SMS.

 

 

ê It is recommended to create a new user for the script usage. The script uses the HTTP-API of the SMS Gateway.

 

 

 

Download-links:

https://github.com/NETWAYS/notify-brevisone

https://github.com/NETWAYS/notify-brevisone/releases/tag/v0.1.0

 

 

1. Download and configure the necessary script

 

For this purpose, you first need the script sendsms.sh.

 

Download it and place it on your Nagios server in the /usr/local/bin/ directory.

 

Create a file "config" in the directory /usr/local/bin/. This file contains the configuration for the script.

 

 

username=<myuser>

 

password=<mypassword>

 

host=<IP Address of the SMS Gateways>

 

#mode=<All modes can be seen here>

 

#insecuressl=true

 

#proxy=[protocol://][user:password@]proxyhost[:port]

 

 

 

2. Configure Nagios

 

In this step commands must now be configured for the SMS configuration in Nagios. Corresponding contacts must also be created.

 

1. Example: Definition for SMS notifications in /etc/nagios3/commands.cfg

 

define command

{

command_name notify-host-by-sms

command_line /usr/local/bin/sendsms.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ - Host $HOSTALIAS$ is $HOSTSTATE$ since $SHORTDATETIME$ info: $HOSTOUTPUT$"

}

 

 

 

define command

{

command_name notify-service-by-sms

command_line /usr/local/bin/sendsms.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ - $SERVICEDESC$ on $HOSTNAME$ state: $SERVICESTATE$ since $SHORTDATETIME$ info: $SERVICEOUTPUT$"

}

 

 

 

2. Example: Definition for a contact in /etc/nagios3/contacts.cfg

 

define contact

{

contact_name Max_Muster

alias Max Muster

host_notification_period 24x7

service_notification_period 24x7

host_notification_options d,u,r

service_notification_options u,c,r

pager 00491701234567

host_notification_commands notify-host-by-sms

service_notification_commands notify-service-by-sms

 

}

 

 

 

 

 

2. Icinga 2

 

 

You can of course use your SMS Gateway to send alarms from Icinga 2 via SMS.

 

 

ê It is recommended to create a new user for the script usage. The script uses the HTTP-API of the SMS Gateway.

 

 

 

Download-links:

https://github.com/NETWAYS/notify-brevisone

https://github.com/NETWAYS/notify-brevisone/releases/tag/v0.1.0

 

 

 

1. Download and configure the necessary script

 

For this purpose, you first need the script sendsms.sh. Download it and place it on your Centreon server in the /usr/local/bin/ directory.

 

Create a file "config" in the directory /usr/local/bin/. This file contains the configuration for the script.

 

 

username=<myuser>

 

password=<mypassword>

 

host=<IP Address of the SMS Gateways>

 

#mode=<All modes can be seen here>

 

#insecuressl=true

 

#proxy=[protocol://][user:password@]proxyhost[:port]

 

 

Lines with beginning # are comments. Commented out options are not necessary.

 

The option insecuressl=true deactivates the SSL Certificate verification.

 

All by the "config" file configured values can be overwritten by parameters.

 

 

2. Configure Icinga 2

 

In this step commands must now be configured for the SMS configuration in Icinga 2. Corresponding contacts must also be created.

 

1. Example: Definition for SMS notifications in /etc/icinga2/conf.d/commands.conf

 

object NotificationCommand "braintower-host-notification" {

import "plugin-notification-command"

command = [ PluginDir + "/sendsms.sh" ]

arguments = {

"-pager" = {

value = "$braintower_pager$"

description = "Telephone number of the SMS recipient"

skip_key = true

}

"-message" = {

value = "$braintower_message$"

description = "SMS message text"

skip_key = true

}

}

vars.braintower_pager = "$user.pager$"

vars.braintower_message = "$notification.type$ - Host $host.display_name$ is $host.state$ since $icinga.long_date_time$ info: $host.output$"

}

 

 

 

object NotificationCommand "braintower-service-notification" {

import "plugin-notification-command"

command = [ PluginDir + "/sendsms.sh" ]

arguments = {

"-pager" = {

value = "$braintower_pager$"

description = "Telephone number of the SMS recipient"

skip_key = true

}

"-message" = {

value = "$braintower_message$"

description = "SMS message text"

skip_key = true

}

}

vars.braintower_pager = "$user.pager$"

vars.braintower_message = "$notification.type$ - Host $host.display_name$ is $host.state$ since $icinga.long_date_time$ info: $host.output$"

}

 

 

 

2. Example: Definition of Host-/Service Templates for SMS notifications in /etc/icings2/conf.d/templates.conf

 

template Notification "braintower-host-notification" {

command = "braintower-host-notification"

states = [ Up, Down ]

types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]

period = "24x7"

}

 

 

 

template Notification "braintower-service-notification" {

command = "braintower-service-notification"

states = [ OK, Warning, Critical, Unknown ]

types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]

period = "24x7"

}

 

 

 

3. Example: Host-/Service Templates for SMS notifications on a host in /etc/icinga2/conf.d/notifications.conf

 

apply Notification "braintower-alerts" to Host {

import "braintower-host-notification"

user_groups = host.vars.notification.sms.groups

assign where host.vars.notification.sms

}

 

 

 

apply Notification "braintower-alerts" to Service {

import "braintower-service-notification"

user_groups = host.vars.notification.sms.groups

assign where host.vars.notification.sms

}

 

 

 

4. Example: Definition of a user group for SMS notifications in /etc/icinga2/conf.d/groups.conf

 

object UserGroup "smsusers" {

display_name = "Icinga 2 SMS Group"

}

 

 

 

5. Example: Adding a contact to the user group for SMS notifications /etc/icinga2/conf.d/users.conf

 

object User "Max_Muster" {

import "generic-user"

display_name = "Max Muster"

groups = [ "smsusers" ]

pager = "00491701234567"

}

 

 

 

 

 

Related articles